using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using AtletIS.DomainModel.Entities.Main;

namespace AtletIS.Database.Mapping.Main
{
    public class CompetitorMap : EntityTypeConfiguration<Competitor>
    {
        public CompetitorMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Firstname)
                .HasMaxLength(50);

            this.Property(t => t.Surname)
                .HasMaxLength(50);

            this.Property(t => t.Sex)
                .HasMaxLength(1);

            this.Property(t => t.ClubId)
                .HasMaxLength(5);

            this.Property(t => t.CountryId)
                .HasMaxLength(3);

            this.Property(t => t.CoachClass)
                .HasMaxLength(5);

            this.Property(t => t.RefereeClass)
                .HasMaxLength(5);

            // Table & Column Mappings
            this.ToTable("Competitors");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Firstname).HasColumnName("Firstname");
            this.Property(t => t.Surname).HasColumnName("Surname");
            this.Property(t => t.Birthdate).HasColumnName("Birthdate");
            this.Property(t => t.Sex).HasColumnName("Sex");
            this.Property(t => t.ClubId).HasColumnName("ClubId");
            this.Property(t => t.CountryId).HasColumnName("CountryId");
            this.Property(t => t.Competitor1).HasColumnName("Competitor");
            this.Property(t => t.CoachClass).HasColumnName("CoachClass");
            this.Property(t => t.RefereeClass).HasColumnName("RefereeClass");
            this.Property(t => t.Active).HasColumnName("Active");
            this.Property(t => t.Sync).HasColumnName("Sync");
            this.Property(t => t.WebId).HasColumnName("WebId");
            this.Property(t => t.Modified).HasColumnName("Modified");

            // Relationships
            this.HasOptional(t => t.Club)
                .WithMany(t => t.Competitors)
                .HasForeignKey(d => d.ClubId);
            this.HasOptional(t => t.Country)
                .WithMany(t => t.Competitors)
                .HasForeignKey(d => d.CountryId);

        }
    }
}
